package com.cetc39.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.cetc39.bean.Role;
import com.cetc39.bean.User;
import com.cetc39.dao.UserDao;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	@Override
	public void save(User user) {
		this.getHibernateTemplate().save(user);
	}

	@Override
	public List<?> findByUserid(String userid, String password) {
		List<?> list = this.getHibernateTemplate().find("FROM User WHERE user_id=? AND pwd=?", new Object[]{userid, password});
		return list;
	}

	@Override
	public void delete(int id) {
		User user = this.getHibernateTemplate().load(User.class, id);
		this.getHibernateTemplate().delete(user);
	}

	@Override
	public void updata(User user) {
		this.getHibernateTemplate().saveOrUpdate(user);
	}

	@Override
	public User findById(int id) {
		User u = this.getHibernateTemplate().get(User.class, id);
		return u;
	}

	@Override
	public List<?> findAll() {
		List<?> uList = this.getHibernateTemplate().find("FROM User");
		return uList;
	}

	@Override
	public List<?> findUserByRole(Role r) {
		List<?> uList = this.getHibernateTemplate().find("FROM User WHERE role=?", r);
		return uList;
	}
}
